﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data;

namespace FreeDocFlow
{
    public class SqlDbManager : DbManager
    {
        public override DbDataReader ExecuteReader(string command)
        {
            var connection = new SqlConnection(connectionString);

            // 1. Instantiate a new command with a query and connection
            SqlCommand cmd = new SqlCommand(command, connection);

            // 2. Call Execute reader to get query results
            SqlDataReader rdr = cmd.ExecuteReader();
            return rdr;
        }

        public override void ExecuteNonQuery(string command)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand(command, connection);
                cmd.ExecuteNonQuery();
            }
        }

        public override DbParameter CreateParameter(string name, object value)
        {
            return new SqlParameter(name, value);
        }

        public override DbDataReader ExecuteReader(string command, DbParameter param)
        {
            var connection = new SqlConnection(connectionString);
            connection.Open();

            SqlCommand cmd = new SqlCommand(command, connection);
            cmd.Parameters.Add(param);

            SqlDataReader rdr = cmd.ExecuteReader();

            return rdr;
        }

        public override void ExecuteNonQuery(string command, DbParameter param)
        {
            throw new NotImplementedException();
        }

        public override DbDataReader ExecuteReader(string command, DbParameterCollection parms)
        {
            throw new NotImplementedException();
        }

        public override void ExecuteNonQuery(string command, DbParameterCollection parms)
        {
            throw new NotImplementedException();
        }
    }
}